package work.huangxin.share.controller.admin;

import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import work.huangxin.share.domain.manhe.Manhe;
import work.huangxin.share.domain.other.UserMessage;
import work.huangxin.share.service.AdminManHeService;
import work.huangxin.share.service.ManheService;
import work.huangxin.share.util.status.BaseResponse;
import work.huangxin.share.util.status.CodeEnum;
import work.huangxin.share.util.status.ResponseData;

import java.util.Objects;

/**
 * @Author: 钟声浩
 * @Date: 2023-05-16 17:07
 * @Desc:
 */
@RestController
@RequestMapping("/wx/admin/api/manHe")
public class AdminManHeController {

    @Autowired
    private AdminManHeService adminManHeService;

    //分页查询所有用户
    @PostMapping("/getAllManHeUser")
    public BaseResponse getAllUserList(@RequestBody Manhe manhe,
                                       @RequestParam Integer pageNum,
                                       @RequestParam Integer pageSize) {
        PageInfo<Manhe> pageInfo = adminManHeService.selectPageUserList(manhe, pageNum, pageSize);
        if (Objects.isNull(pageInfo)) {
            return ResponseData.out(CodeEnum.NOT_FOUND, "数据丢失");
        }
        return ResponseData.success(pageInfo);
    }

    //查看纸条详情
    @GetMapping("/getDetail/{id}")
    public BaseResponse getDetail(@PathVariable("id") Long id) {
        Manhe manhe = adminManHeService.getDetail(id);
        return ResponseData.success(manhe);
    }

    //删除纸条
    @PostMapping("/deleteManHeById/{id}")
    public BaseResponse deleteManHeById(@PathVariable("id") Long id) {
        int count = adminManHeService.deleteManHeById(id);
        if (count <= 0) {
            return ResponseData.out(CodeEnum.NOT_FOUND, "删除数据失败!");
        }
        return ResponseData.success();
    }

    //添加纸条
    @PostMapping("/addManHe")
    public BaseResponse addManHe(@RequestBody Manhe manhe) {
        int count = adminManHeService.addManHe(manhe);
        if (count <= 0) {
            return ResponseData.out(CodeEnum.FAIL, "添加纸条失败!");
        }
        return ResponseData.success();
    }
}
